<?php
if(!function_exists('csrc')){
    function csrc($src){
        return env('CDN') . $src;
    }
}

if(!function_exists('is_phone')){
    function is_phone($phone){
        return preg_match('/^(13|14|15|17|18)[0-9]{9}$/',$phone);
    }
}

if(!function_exists('cp')){
    function cp($src,$columns){
        $ret = [];
        foreach($columns as $k){
            $ret[$k] = $src[$k];
        }
        return $ret;
    }
}

if(!function_exists('percent')){
    function percent($has,$total){
        if($has == 0){
            return '0.00%';
        }
        if($total == 0){
            return '--';
        }
        return round($has / $total * 100,2) . '%';
    }
}

if(!function_exists('divide')){
    function divide($has,$total){
        if($has == 0){
            return 0;
        }
        if($total == 0){
            return '--';
        }
        return round($has / $total * 100,2);
    }
}

if(!function_exists('gcd')){
    function gcd($m,$n){
        return ($m < $n) ? gcd2($m,$n % $m) : gcd2($n, $m % $n);
    }
}

if(!function_exists('ratio')){
    function ratio($m,$n){
        $m = (int)$m;
        $n = (int)$n;
        if($m == 0 || $n == 0){
            return $m . ':' . $n;
        }
        $gcd = gcd($m,$n);
        return $m / $gcd . ':' .$n / $gcd;
    }
}

if(!function_exists('date_int_to_str')){
    function date_int_to_str($int_Date){
        return substr($int_Date,0,4) . '-' . substr($int_Date,4,2).'-'.substr($int_Date,6,2);
    }
}
